
#include "a.h"

void int_link(linklist front,linklist rear){//初始化队列
   front->data =0;
   front->next =rear;
   rear->next =front;

   return;
}

void add_link(linklist front ,linklist rear){//尾插
	
		linklist t;
		 t=(node*)malloc(sizeof(node));
		 printf("please imput data:");
		 scanf("%d",&t->data );
		 t->next=NULL;
	if(rear->next==front){
	      front->next =t;
		  rear->next =t;
	}else{
		 rear->next->next=t;
		 rear->next=t;
	  
      }
      front->data++;
      return;
}

void print_link(linklist front,linklist rear){//打印队列
	if(rear->next==front){
		printf("ERROR linklist is empty\n");
		return;
	}
	linklist s1;
	
	s1=front;
   
   do{
   	s1=s1->next;
    printf("%d->",s1->data );
    
   }while(s1->next!=NULL);
	printf("\n\n");
	
	
	
}
void delete_link(linklist front,linklist rear){//头删
	linklist s1;
	s1=front->next ;
	if(rear->next==front){
	     printf("ERROR linklist is empty\n");
	     return;
	}else if(front->next ==rear->next ){
	   	free(s1);
	   	front->next =rear;
		rear->next =front;
	    front->data--;
    }else{
      	front->next=s1->next ;
      	free(s1);
      	front->data--;
	  }
}

void find_link(linklist front,linklist rear,int t){//按值查找
    linklist s1;
	s1=front;
	int i;
    for(i=0;i<front->data ;i++){
    	s1=s1->next;
    	if(t==s1->data ){
    		printf("successfully find:place of %d\n",i+1);
		}
    	
	}


}

void whole_delete_link(linklist front,linklist rear){//销毁队列
	int i=front->data ;
	 for(;i>1;i--){
	 	linklist s1;
	 	s1=front->next ;
	 	front->next =s1->next ;
	 	free(s1);
	 }
	linklist s1;
	s1=front->next ;
	front->next =rear;
	rear->next =front;
	front->data =0;
     free(s1);
	
}
void menu(){//菜单
	printf("*******************************\n");
	printf("***        queue            ***\n");
	printf("***     1.add_queue         ***\n");
	printf("***     2.delete_queue      ***\n");
	printf("***     3.find_queue        ***\n");
	printf("***     4.whole_delete      ***\n");
	printf("***     5.printf_queue      ***\n");
	printf("***     0.exit              ***\n");
	printf("*******************************\n");
	printf("\n\n");
}


